package cn.merryyou.jpa.domain.primarykey;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import javax.persistence.Embeddable;
import java.io.Serializable;

@Getter
@Setter
@NoArgsConstructor
@Embeddable
@ToString
public class UserPackagePK implements Serializable {

    private static final long serialVersionUID = -6844245667614247243L;
    private Integer user;
    private Integer redPackage;

    public boolean equals(Object object) {
        if (this == object)
            return true;
        if (!(object instanceof UserPackagePK))
            return false;
        final UserPackagePK other = (UserPackagePK) object;
        if (this.user != null && other.getUser() != null) {
            if (user == other.getUser()) {
                if (redPackage != null && other.getRedPackage() != null && redPackage== other.getRedPackage()) {
                    return true;
                } else {
                    return false;
                }
            } else {
                return true;
            }
        } else
            return false;
    }

    public int hashCode() {
        return super.hashCode() +
                (user != null ? user.hashCode() : 0) +
                (redPackage != null ? redPackage.hashCode() : 0);
    }

}
